package com.example.controller;

import com.example.dto.Result;
import com.example.entity.Topic;
import com.example.service.TopicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/topic")
@Api("对主题表的操作")
public class TopicController {

    @Autowired
    private TopicService topicService;

    @RequestMapping(value = "/getTopic", method = RequestMethod.GET)
    @ApiOperation(value = "获取所有主题信息", notes = "返回的是Result类型，数据段是所有句子的json格式")
    public Result<List<Topic>> getTopic(){
        Result<List<Topic>> result = new Result<>();
        List<Topic> list = topicService.getTopics();
        return result.ok("所有主题信息", list);
    }

    @RequestMapping(value = "/getTopicByName", method = RequestMethod.POST)
    @ApiOperation(value = "模糊查询主题信息", notes = "传递参数：模糊字符（name）")
    public Result<List<Topic>> getTopicByName(@RequestParam("name") String name){
        Result<List<Topic>> result = new Result<>();
        List<Topic> list = topicService.getTopicsByName(name);
        return result.ok("模糊查询结果", list);
    }

    @RequestMapping(value = "/setTopic={name}", method = RequestMethod.GET)
    @ApiOperation(value = "管理员添加主题", notes = "该接口管理员调用，普通用户不允许调用")
    public void addTopic(@PathVariable("name") String name){
        topicService.addTopic(name);
    }

}
